package com.project.controller;


import com.common.annotation.Log;
import com.common.core.controller.BaseController;
import com.common.core.domain.AjaxResult;
import com.common.core.page.PageDomain;
import com.common.core.page.TableDataInfo;
import com.common.enums.BusinessType;
import com.github.pagehelper.PageHelper;
import com.project.domain.bo.DmBudgetStandardBo;
import com.project.domain.vo.DmBudgetStandardVo;
import com.project.service.IBudgetStandardService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.Pattern;
import java.util.Date;
import java.util.List;

/**
 * 预算标准Controller
 *
 * @author baige
 * @date 2025-02-08
 */
@Api(tags = "预算标准")
@RestController
@RequestMapping("/project/ysbzsz")
public class BudgetStandardController extends BaseController {
    @Autowired
    private IBudgetStandardService dmBudgetStandardService;

    /**
     * 查询预算标准列表
     */
    @ApiOperation(value = "获取集合")
//    @PreAuthorize("@ss.hasPermi('project:ysbzsz:list')")
    @GetMapping("/list")
    public TableDataInfo list(@ApiParam(value = "项目分类,zXProject>纵向,yfContract->横向,xJProject->校级", required = true)
                              @RequestParam(value = "projectClass", required = true)
                              @Pattern(regexp = "zXProject|yfContract|xJProject", message = "项目性质,zXProject->纵向,yfContract->横向,xJProject->校级")
                              String projectClass,
                              PageDomain page) {
        PageHelper.startPage(page.getPageNum(), page.getPageSize());
        List<DmBudgetStandardVo> list = dmBudgetStandardService.selectDmBudgetStandardList(projectClass);
        return getDataTable(list);
    }


    /**
     * 详细信息
     */
    @ApiOperation(value = "获取详细信息")
//    @PreAuthorize("@ss.hasPermi('project:ysbzsz:query')")
    @GetMapping(value = "/{ID}")
    public AjaxResult getInfo(@PathVariable("ID") String ID) {
        return success(dmBudgetStandardService.selectDmBudgetStandardByID(ID));
    }

    /**
     * 新增预算标准
     */
    @ApiOperation(value = "新增标准")
//    @PreAuthorize("@ss.hasPermi('project:ysbzsz:add')")
    @Log(title = "预算标准", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DmBudgetStandardBo dmBudgetStandard) {
        int code = dmBudgetStandardService.insertDmBudgetStandard(dmBudgetStandard);
        switch (code){
            case 100:
                return error("科目编号已存在");
            case 200:
                return success();
            case 500:
                return error();
            default:
                return success();

        }
    }

    /**
     * 修改预算标准
     */
    @ApiOperation(value = "修改标准")
//    @PreAuthorize("@ss.hasPermi('project:ysbzsz:edit')")
    @Log(title = "预算标准", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DmBudgetStandardBo dmBudgetStandard) {
        return toAjax(dmBudgetStandardService.updateDmBudgetStandard(dmBudgetStandard));
    }

    /**
     * 删除预算标准
     */
    @ApiOperation(value = "删除标准")
//    @PreAuthorize("@ss.hasPermi('project:ysbzsz:remove')")
    @Log(title = "预算标准", businessType = BusinessType.DELETE)
    @DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable String id) {
        return toAjax(dmBudgetStandardService.deleteDmBudgetStandardByID(id));
    }


    //---------------------------其余接口----------------------------------------

    /**
     * 获取最大的科目前缀
     */
    @ApiOperation(value = "获取最大的科目前缀")
    @GetMapping("/getMaxPrefix")
    public AjaxResult getMaxPrefix(@ApiParam(value = "项目分类,zXProject->纵向,yfContract->横向,xJProject->校级", required = true)
                                   @RequestParam(value = "projectClass", required = true)
                                   @Pattern(regexp = "zXProject|yfContract|xJProject")
                                   String projectClass) {
        return AjaxResult.success("查询成功",dmBudgetStandardService.getMaxPrefix(projectClass));
    }


    /**
     *  业务 ->根据项目分类id和立项时间,查询预算标准id
     */
    @ApiOperation(value = "业务 zjy ->根据项目分类id和立项时间,查询预算标准id-")
    @GetMapping("/getYsbzIdByxmflId")
    public AjaxResult getYsbzIdByxmflId(@ApiParam(value = "项目分类id", required = true)
                                        @RequestParam(value = "projectClassId", required = true)
                                        String projectClassId,
                                        @ApiParam(value = "项目立项时间", required = true)
                                        @RequestParam(value = "projectDate", required = true)
                                        Date projectDate) {
        return AjaxResult.success(dmBudgetStandardService.getYsbzIdByxmflId(projectClassId,projectDate));
    }


    /**
     *  业务 ->根据项目分类id和立项时间,查询预算科目集合
     */
    @ApiOperation(value = "业务 cw ->根据项目分类id和立项时间,查询预算科目集合")
    @GetMapping("/getYskmListByxmflId")
    public AjaxResult getYskmListByxmflId(@ApiParam(value = "项目分类id", required = true)
                                        @RequestParam(value = "projectClassId", required = true)
                                        String projectClassId,
                                        @ApiParam(value = "项目立项时间", required = true)
                                        @RequestParam(value = "projectDate", required = true)
                                        Date projectDate) {
        return AjaxResult.success(dmBudgetStandardService.getYskmListByxmflId(projectClassId,projectDate));
    }

}
